package com.bigdata.bookinfo.pojo;

import lombok.NoArgsConstructor;
import org.apache.hadoop.io.Writable;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;

@NoArgsConstructor
public class Book implements Writable {
    private String title;

    private String comment;

    private String recommend;
    private String author;
    private String date;

    private String press;

    private String price_n;

    private String price_r;

    private String price_s;

    private String href;

    public String getTitle() {
        return title;
    }

    public Book(String title, String comment, String recommend, String author, String date, String press, String price_n, String price_r, String price_s, String href) {
        this.title = title;
        this.comment = comment;
        this.recommend = recommend;
        this.author = author;
        this.date = date;
        this.press = press;
        this.price_n = price_n;
        this.price_r = price_r;
        this.price_s = price_s;
        this.href = href;
    }

    @Override
    public void write(DataOutput dataOutput) throws IOException {
        dataOutput.writeUTF(title);
        dataOutput.writeUTF(comment);
        dataOutput.writeUTF(recommend);
        dataOutput.writeUTF(author);
        dataOutput.writeUTF(date);
        dataOutput.writeUTF(press);
        dataOutput.writeUTF(price_n);
        dataOutput.writeUTF(price_r);
        dataOutput.writeUTF(price_s);
        dataOutput.writeUTF(href);
    }

    @Override
    public void readFields(DataInput dataInput) throws IOException {
        this.title = dataInput.readUTF();
        this.comment = dataInput.readUTF();
        this.recommend = dataInput.readUTF();
        this.author = dataInput.readUTF();
        this.date = dataInput.readUTF();
        this.press = dataInput.readUTF();
        this.price_n = dataInput.readUTF();
        this.price_r = dataInput.readUTF();
        this.price_s = dataInput.readUTF();
        this.href = dataInput.readUTF();
    }

    @Override
    public String toString() {
        return comment+"\t"+recommend+"\t"+author+"\t"+date+"\t"+press+"\t"+price_n+"\t"+price_r+"\t"+price_s+"\t"+href;
    }
}
